/* eslint-disable no-param-reassign */
const pattern_1 = /^.*([0-9])+.*$/i; //数字
const pattern_2 = /[a-z]/; //小写字母
const pattern_3 = /[A-Z]/; //大写字母
const pattern_4 =
  /[`~!@#$%^&*()\-_+=\\|{}':;\",\[\].<>\/?~！@#￥%……&*（）——+|{}【】‘；：”“’。，、？]/; //特殊字符

const getPwdStrength = (pwd) => {
  if (!pwd) {
    return;
  } else {
    let level = 0;
    pwd = pwd.trim();
    if (pwd.length >= 6) {
      if (pattern_1.test(pwd)) {
        level++;
      }
      if (pattern_2.test(pwd)) {
        level++;
      }
      if (pattern_3.test(pwd)) {
        level++;
      }
      if (pattern_4.test(pwd)) {
        level++;
      }
      if (level > 4) {
        level = 4;
      }
    }
    if (level == 0) {
      return 'poor';
    } else if (level == 1) {
      return 'poor';
    } else if (level == 2) {
      return 'pass';
    } else if (level == 3) {
      return 'middle';
    } else {
      return 'ok';
    }
  }
};

const getPwdStrengthlength = (pwd) => {
  if (!pwd) {
    return 0;
  } else {
    let level = 0;
    pwd = pwd.trim();
    if (pwd.length >= 6) {
      if (pattern_1.test(pwd)) {
        level++;
      }
      if (pattern_2.test(pwd)) {
        level++;
      }
      if (pattern_3.test(pwd)) {
        level++;
      }
      if (pattern_4.test(pwd)) {
        level++;
      }
      if (level > 4) {
        level = 4;
      }
    }
    return level;
  }
};

export { getPwdStrength, getPwdStrengthlength };
